16
Beginner’s Guide to Code Algorithms
16
Your code should look like this:
Sub Macro1()
'
' Macro1 Macro
'
Sheets("Sheet1").Select
Range("A1:B3").Select
Selection.Copy
Sheets("Sheet2").Select
ActiveSheet.Paste
End Sub
FIGURE 2.9 Macro1 code.
This view is the view of the Visual Basic Applications Window of excel. See the
picture below. Each program is a “project” as you can have multiple programs for the
same workbook. The name of the project is defined by the workbook—in this case we
haven’t named it yet, so it appears as Book1.
FIGURE 2.10 VBA Project.
Now you should be able to run this program.
To see it is working, erase the data we just copied into Sheet2.
Come back to the Visual Basic window and click on the play button circled in
red above.
You will see that the copied text now reappears in Sheet2!
2.2 HOW TO GET WARMED UP
Let’s get straight to the game now.
It is a game of Tic Tac Toe—the age-old game that has been played over the centuries.
A different version of this game was played by Romans in the first century bc and it
was called “Terni Lapilli” (three pebbles at a time). They played it with the same nine